package com.moyangfenghun.javabase.componet.flexlisten;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.digest.MD5;
import com.moyangfenghun.javabase.model.SysUserEntity;
import com.mybatisflex.annotation.UpdateListener;

public class SysUserUpdateListener implements UpdateListener {
    @Override
    public void onUpdate(Object o) {
        setSysUserPassword((SysUserEntity) o);
    }

    static void setSysUserPassword(SysUserEntity o) {
        if(o.getPassword()!=null){
            String salt = RandomUtil.randomString(4);
            String pass = MD5.create().digestHex16(salt + o.getPassword());
            o.setPassword(pass);
//            o.setSalt(salt);
        }
    }
}
